<template>
  <a-modal
    :visible="visible"
    title="培养计划详细信息"
    okText='提交审核结果'
    cancelText="关闭"
    :confirmLoading="confirmLoading"
    :width="1200"
    style="top: 20px;"
    :bodyStyle="{
      'max-height': '60vh',
      overflow: 'auto'
    }"
    @cancel="() => { $emit('cancel') }"
    @ok="submitCheck"
    >
    <detail-list>
      <detail-list-item term="姓名">{{ planInfo.pyjh.xm }}&emsp;</detail-list-item>
      <detail-list-item term="学号">{{ planInfo.pyjh.xh }}&emsp;</detail-list-item>
      <detail-list-item term="培养单位">{{ planInfo.pyjh.dwmc }}&emsp;</detail-list-item>
      <detail-list-item term="专业">{{ planInfo.pyjh.zymc }}&emsp;</detail-list-item>
      <detail-list-item term="年级">{{ planInfo.pyjh.sznj }}&emsp;</detail-list-item>
      <detail-list-item term="培养方案">{{ planInfo.pyjh.pyfamc }}&emsp;</detail-list-item>
    </detail-list>
    <a-table
      rowKey="id"
      :columns="columns"
      :dataSource="planInfo.pyjhkcList"
      :pagination="false"
      :scroll="{ y: 300, x: 1200 }">
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
      <template slot="sfmbkc" slot-scope="sfmbkc, record">
        <a-checkbox @change="e => handleChange(e.target.checked, record)" :defaultChecked="+sfmbkc == 1"/>
        通过
      </template>
      <a-input slot-scope="sfmbkc, record" v-model="record.shyj" slot="shyj"/>
    </a-table>
    <credit-table :pyjh="planInfo.pyjh"/>
  </a-modal>
</template>

<script>
import DetailList from '~/tool/DetailList'
import creditTable from '../components/creditTable.vue'
const DetailListItem = DetailList.Item

export default {
  props: ['visible'],
  data () {
    return {
      planInfo: {
        pyjh: {},
        pyjhkcList: []
      },
      columns: [
        {
          title: '序号',
          width: '50px',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '课程代码',
          width: '120px',
          dataIndex: 'kcdm'
        },
        {
          title: '课程名称',
          width: '150px',
          dataIndex: 'kcmc'
        },
        {
          title: '学时',
          width: '60px',
          dataIndex: 'xs'
        },
        {
          title: '学分',
          width: '60px',
          dataIndex: 'xf'
        },
        {
          title: '修课要求',
          width: '100px',
          dataIndex: 'bxhxxmc'
        },
        {
          title: '课程类型',
          width: '100px',
          dataIndex: 'kclxmc'
        },
        {
          title: '是否学位课',
          width: '60px',
          dataIndex: 'sfxwkmc'
        },
        {
          title: '审核状态',
          dataIndex: 'sfmbkc',
          width: '100px',
          scopedSlots: { customRender: 'sfmbkc' }
        },
        {
          title: '审核意见',
          dataIndex: 'shyj',
          width: '200px',
          scopedSlots: { customRender: 'shyj' }
        }
      ],
      confirmLoading: false
    }
  },
  components: {
    DetailList,
    DetailListItem,
    creditTable
  },
  methods: {
    getInfo (id) {
      this.$api.cultivate.planDetail(id).then(res => {
        this.planInfo = res.data
      })
    },
    handleChange (e, kc) {
      kc.sfmbkc = e ? 1 : 0
    },
    submitCheck () {
      console.log(this.planInfo.pyjhkcList)
      // let index = this.planInfo.pyjhkcList.findIndex(kc => {
      //   return !kc.shyj
      // })
      this.confirmLoading = true
      let params = {
        pyjhId: this.planInfo.pyjh.id,
        pyjhkcshList: this.planInfo.pyjhkcList.map(kc => {
          return {
            kcshzt: +kc.sfmbkc === 1 ? '02' : '03',
            pyjhkcId: kc.id,
            shyj: kc.shyj ? kc.shyj : ''
          }
        })
      }
      this.$api.cultivate.planCheck(params).then(res => {
        this.$message.success(res.msg)
        this.$emit('cancel')
        this.$emit('refresh')
      }).finally(() => {
        this.confirmLoading = false
      })
    }
  }
}
</script>

<style scoped lang="less">
.kc-table{
  margin: 10px auto;
  td{
    padding: 5px;
  }
}
</style>
